﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace Autoverwaltung.GUI
{
    public class ColorToSolidColorBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is Color)
            {
                return new SolidColorBrush((Color)value);
            }
            else
            {
                if(value is System.Drawing.Color)
                {
                    System.Drawing.Color c = (System.Drawing.Color)value;
                    return new SolidColorBrush(Color.FromArgb(c.A, c.R, c.G, c.B));
                }
            }

            return Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            SolidColorBrush scb = value as SolidColorBrush;

            if (scb != null)
            {
                Color c = scb.Color;
                return System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
            }

            return System.Drawing.Color.FromArgb(255, 0, 0, 0);
        }
    }
}
